package com.watson.juc.testlist;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @author watson
 * @date 2021/7/30 10:28
 * @Description: TODO
 **/
public class CountDownLatchDemo {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "out");
                //-1,谁先出不管，顺序不管
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        try {
            //
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // -1
//        countDownLatch.countDown();
        System.out.println("close");
    }


}
